//form提交时必填项是否添加
function formSure(formName) {
    let status = false
    this.$refs[formName].validate((valid) => {
        if (valid) {
            status = true
        } else {
            status = false
        }
    })
    return status
}

//form清空
function formClear(formName, form) {
    for (const item in form) {
        if (form[item] === null) {
            form[item] = null;
        } else if (Object.prototype.toString.call(form[item]) === '[object Object]') {
            form[item] = {};
        } else if (Object.prototype.toString.call(form[item]) === '[object Array]') {
            form[item] = [];
        } else if (Object.prototype.toString.call(form[item]) === '[object Number]') {
            if (item === 'pageNum') {
                form[item] = 1;
            } else if (item !== 'pageSize') {
                form[item] = 0;
            }
        } else {
            form[item] = undefined;
        }
    }
    setTimeout(_ => {
        this.$refs[formName].clearValidate();
    }, 1000)
}

const plugin = {
    install(Vue) {
        Vue.prototype.formSure = formSure
        //清空为默认值
        Vue.prototype.formClear = formClear
    }
}
export default plugin
